package com.itheima.controller.pms;

import com.itheima.core.R;
import com.itheima.pojo.pms.PmsSkuStock;
import com.itheima.service.pms.PmsSkuStockService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/sku")
public class PmsSkuStockController {

    @DubboReference
    private PmsSkuStockService skuStockService;

    /**
     * 批量更新sku库存信息
     * @param skuStockList
     * @return
     */
    @PostMapping("/update/{pid}")
    public R updataSku(@RequestBody List<PmsSkuStock> skuStockList, @PathVariable Integer pid){
        skuStockService.updateSku(skuStockList,pid);
        return R.success();
    }

    /**
     * 根据商品ID及sku编码模糊搜索sku库存
     * @param keyword
     * @return
     */
    @GetMapping("/{pid}")
    public R likeSkuStock (@RequestParam(required = false) String keyword, @PathVariable Integer pid){
        List<PmsSkuStock> skuStocks = skuStockService.likeSkuStock(keyword, pid);
        return R.success(skuStocks);
    }
}
